<?php


abstract class BaseCtControl extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id;


	
	protected $entidad_prestadora_id;


	
	protected $fecha;


	
	protected $codigo_archivo;


	
	protected $total_registros;


	
	protected $total_registros_numero;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getId()
	{

		return $this->id;
	}

	
	public function getEntidadPrestadoraId()
	{

		return $this->entidad_prestadora_id;
	}

	
	public function getFecha()
	{

		return $this->fecha;
	}

	
	public function getCodigoArchivo()
	{

		return $this->codigo_archivo;
	}

	
	public function getTotalRegistros()
	{

		return $this->total_registros;
	}

	
	public function getTotalRegistrosNumero()
	{

		return $this->total_registros_numero;
	}

	
	public function setId($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = CtControlPeer::ID;
		}

	} 
	
	public function setEntidadPrestadoraId($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->entidad_prestadora_id !== $v) {
			$this->entidad_prestadora_id = $v;
			$this->modifiedColumns[] = CtControlPeer::ENTIDAD_PRESTADORA_ID;
		}

	} 
	
	public function setFecha($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->fecha !== $v) {
			$this->fecha = $v;
			$this->modifiedColumns[] = CtControlPeer::FECHA;
		}

	} 
	
	public function setCodigoArchivo($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->codigo_archivo !== $v) {
			$this->codigo_archivo = $v;
			$this->modifiedColumns[] = CtControlPeer::CODIGO_ARCHIVO;
		}

	} 
	
	public function setTotalRegistros($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->total_registros !== $v) {
			$this->total_registros = $v;
			$this->modifiedColumns[] = CtControlPeer::TOTAL_REGISTROS;
		}

	} 
	
	public function setTotalRegistrosNumero($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->total_registros_numero !== $v) {
			$this->total_registros_numero = $v;
			$this->modifiedColumns[] = CtControlPeer::TOTAL_REGISTROS_NUMERO;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->id = $rs->getString($startcol + 0);

			$this->entidad_prestadora_id = $rs->getString($startcol + 1);

			$this->fecha = $rs->getString($startcol + 2);

			$this->codigo_archivo = $rs->getString($startcol + 3);

			$this->total_registros = $rs->getString($startcol + 4);

			$this->total_registros_numero = $rs->getInt($startcol + 5);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 6; 
		} catch (Exception $e) {
			throw new PropelException("Error populating CtControl object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(CtControlPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			CtControlPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(CtControlPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = CtControlPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += CtControlPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


			if (($retval = CtControlPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}



			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = CtControlPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getEntidadPrestadoraId();
				break;
			case 2:
				return $this->getFecha();
				break;
			case 3:
				return $this->getCodigoArchivo();
				break;
			case 4:
				return $this->getTotalRegistros();
				break;
			case 5:
				return $this->getTotalRegistrosNumero();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = CtControlPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getEntidadPrestadoraId(),
			$keys[2] => $this->getFecha(),
			$keys[3] => $this->getCodigoArchivo(),
			$keys[4] => $this->getTotalRegistros(),
			$keys[5] => $this->getTotalRegistrosNumero(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = CtControlPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setEntidadPrestadoraId($value);
				break;
			case 2:
				$this->setFecha($value);
				break;
			case 3:
				$this->setCodigoArchivo($value);
				break;
			case 4:
				$this->setTotalRegistros($value);
				break;
			case 5:
				$this->setTotalRegistrosNumero($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = CtControlPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setEntidadPrestadoraId($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setFecha($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setCodigoArchivo($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setTotalRegistros($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setTotalRegistrosNumero($arr[$keys[5]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(CtControlPeer::DATABASE_NAME);

		if ($this->isColumnModified(CtControlPeer::ID)) $criteria->add(CtControlPeer::ID, $this->id);
		if ($this->isColumnModified(CtControlPeer::ENTIDAD_PRESTADORA_ID)) $criteria->add(CtControlPeer::ENTIDAD_PRESTADORA_ID, $this->entidad_prestadora_id);
		if ($this->isColumnModified(CtControlPeer::FECHA)) $criteria->add(CtControlPeer::FECHA, $this->fecha);
		if ($this->isColumnModified(CtControlPeer::CODIGO_ARCHIVO)) $criteria->add(CtControlPeer::CODIGO_ARCHIVO, $this->codigo_archivo);
		if ($this->isColumnModified(CtControlPeer::TOTAL_REGISTROS)) $criteria->add(CtControlPeer::TOTAL_REGISTROS, $this->total_registros);
		if ($this->isColumnModified(CtControlPeer::TOTAL_REGISTROS_NUMERO)) $criteria->add(CtControlPeer::TOTAL_REGISTROS_NUMERO, $this->total_registros_numero);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(CtControlPeer::DATABASE_NAME);

		$criteria->add(CtControlPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setEntidadPrestadoraId($this->entidad_prestadora_id);

		$copyObj->setFecha($this->fecha);

		$copyObj->setCodigoArchivo($this->codigo_archivo);

		$copyObj->setTotalRegistros($this->total_registros);

		$copyObj->setTotalRegistrosNumero($this->total_registros_numero);


		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new CtControlPeer();
		}
		return self::$peer;
	}

} 